package com.treasure.mall.biz.repository.live;

import com.treasure.mall.biz.base.JpaSearchableRepository;
import com.treasure.mall.biz.entity.live.LiveRoomImagesPO;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * 
 * <p>
 * +---------------------------------------------------------
 * * @package: com.treasure.mall.biz.repository.live
 * * @author: guomw (guomwchen@foxmail.com)
 * * @date: 2020/9/11 11:36 上午
 * * @since: V1.0.0
 * +---------------------------------------------------------
 * 注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的
 * 
 */
@Repository
public interface LiveRoomImagesRepository extends JpaSearchableRepository<LiveRoomImagesPO, Long> {


    LiveRoomImagesPO findFirstByRoomIdAndPushedIsTrueAndDeletedIsFalseOrderByPushTimeDesc(Long roomId);


    /**
     * 重置推送状态
     *
     * @param roomId
     */
    @Query("update LiveRoomImagesPO set pushed=false where roomId=?1 and pushed=true ")
    @Modifying
    @Transactional(rollbackFor = RuntimeException.class)
    void resetPushed(Long roomId);
}
